import { createDiscreteApi } from 'naive-ui'

/**
 * 用法：
 * useMessage().success("xxx")
 * @returns
 */
var kva_message = null
export const useMessage = () => {
  if (!kva_message) {
    const {message} = createDiscreteApi(['message'])
    kva_message = message
  }
  //是否关闭当前实例其他的所有的message
  //kva_message.destroyAll()
  return kva_message
}

/**
 * 用法：
 * https://www.naiveui.com/zh-CN/os-theme/components/dialog
 * useDialog().[success/warning/error/]({
 title: '警告',
 content: '你确定？',
 positiveText: '确定',
 negativeText: '不确定',
 onPositiveClick: () => {
 message.success('确定')
 },
 onNegativeClick: () => {
 message.error('不确定')
 }
 })
 * @returns
 */
var kva_dialog = null
export const useDialog = () => {
  if (!kva_dialog) {
    const {dialog} = createDiscreteApi(['dialog'])
    kva_dialog = dialog
  }
  return kva_dialog
}

/**
 * 用法：
 * useNotification().info("xxx")
 * useNotification().success("xxx")
 * useNotification().warning("xxx")
 * useNotification().error("xxx")
 * @returns
 */
var kva_notification = null
export const useNotification = () => {
  if (!kva_notification) {
    const {notification} = createDiscreteApi(['notification'])
    kva_notification = notification
  }
  //是否关闭全局
  //kva_notification.destoryAll()
  return kva_notification
}

/**
 * 用法：
 * useLoading().start()
 * useLoading().finish()
 * @returns
 */
var ksd_uloadingBar = null
export const useLoading = () => {
  if (!ksd_uloadingBar) {
    const {loadingBar} = createDiscreteApi(['loadingBar'])
    ksd_uloadingBar = loadingBar
  }
  return ksd_uloadingBar
}
